package com.zzc.controller;

import com.zzc.domain.Product;
import com.zzc.repository.ProductESRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class ElasticSearchController {

    @Autowired
    private ProductESRepository productESRepository;

    @GetMapping("/search")
    public String searchProduct(String productName, Model model){

        //返回ElasticSearch搜索的结果
        List<Product> productList = productESRepository.findByproductName(productName);

        model.addAttribute("productList",productList);

        return "search";
    }

}
